import request from '@/utils/request'

// 图片验证码
export function getCaptcha(data) {
  return request({
    url: '/get-captcha',
    method: 'post',
    data
  })
}

// 登录
export function userLogin(username, password) {
  return request({
    url: '/login',
    method: 'post',
    headers: {
      isToken: false
    },
    data: {'username': username, 'password': password}
  })
}

export function userRegister(username, nickName, email, password, rpassword, emailAuthCode) {
  return request({
    url: '/user/register',
    method: 'post',
    headers: {
      isToken: false
    },
    data: {
      "username": username,
      "nickName": nickName,
      "email": email,
      "password": password,
      "rpassword": rpassword,
      "authCode": emailAuthCode
    }
  })
}

//获取邮箱验证码
export function getEmailAuthCode(email) {
  return request({
    url: '/user/getEmailAuthCode/' + email,
    method: 'get',
    headers: {
      isToken: false
    }
  })
}


export function logout() {
  return request({
    url: '/logout',
    method: 'post'
  })
}

export function getUserInfo() {
  return request({
    url: '/user/userInfo',
    method: 'get',
  })
}


export function savaUserInfo(userinfo) {
  return request({
    url: '/user/userInfo',
    method: 'put',
    data: userinfo
  })
}

export function forgetPassword(email, emailAuthCode, newPassword) {
  return request({
    url: '/user/forget',
    method: 'put',
    data: {"email": email, "newPassword": newPassword, "authCode": emailAuthCode}
  })
}

export function updatePassword(newPassword, rePassword) {
  return request({
    url: '/user/update',
    method: 'put',
    data: {"password": newPassword, "rePassword": rePassword}
  })
}
